﻿<%@ Page Title="" Language="C#" Debug="true" ValidateRequest="false" MasterPageFile="~/Views/Shared/Admin.Master"
    Inherits="System.Web.Mvc.ViewPage<ThietBiSo.LinQDB.SanPham>" %>

<%@ Import Namespace="ThietBiSo.LinQDB" %>
<%@ Import Namespace="ThietBiSo.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Website - bảng điều khiển
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        function submitForm() {
            if (checkForm()) {
                document.forms[0].submit();
            }
        }


        function checkForm() {
            var flag = true;
            var F = document.forms[0];
            var TenSP = document.getElementById("TenSP").value;
            
            var HinhAnh = document.getElementById("HinhAnh").value;           

            if (TenSP == null || TenSP == "") {
                alert("Chưa nhập tên sản phẩm");
                F.TenSP.focus();
                flag = false;

            }
            else if (HinhAnh == null || HinhAnh == "") {
                alert("Chưa chọn hình ảnh");
                F.HinhAnh.focus();
                flag = false;

            }
           
            return flag;
        }
    
               
    </script>
    <%
   
        MDanhMuc mdm = new MDanhMuc();
        var loaisp = mdm.FindAll();

       // int cbNhom = int.Parse(Request.QueryString["cbNhom"]);
    %>
    <% using (Html.BeginForm("Create", "SanPham", FormMethod.Post, new { @enctype = "multipart/form-data" }))
       { %>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <legend class="">Thêm mới sản phẩm</legend>
        <table width="100%" cellpadding="2" cellspacing="0">
            <tr>
                <td>
                    
                    <input type="button" value="Thêm" class="btn" onclick="submitForm();" />
                    
                </td>
                <td>
                    <%: Html.ActionLink("Quay lại", "", new { cbNhom = ViewData["urlcbNhom"]})%>
                </td>
            </tr>
            <tr>
                <td class="tableLabel">
                    Danh mục
                </td>
                <td style="color: Red; font-weight: bold;">
                    <%:Html.Hidden("cbNhom", ViewData["urlcbNhom"])%>      
                       <%:mdm.TenDanhMuc((int.Parse((string)ViewData["urlcbNhom"]))) %>            
                </td>
            </tr>
           
            <tr>
                <td class="tableLabel">
                    Tên SP
                </td>
                <td class="tableField">
                    <%:Html.TextBox("TenSP", null, new { @style="width:600px" })%>
                </td>
            </tr>
            <tr>
                <td class="tableLabel">
                    Hình đại diện
                </td>
                <td class="tableField">
                    <%:Html.TextBox("HinhAnh")%>
                    <input type="button" value="Chọn ..." id="btnSelectImg" name="btnSelectImg" />
                    <script type="text/javascript">
                        $(document).ready(function () {
                            $("#btnSelectImg").click(function () {
                                var finder = new CKFinder();
                                finder.selectActionFunction = function (fileUrl) {
                                    $('#HinhAnh').val(fileUrl);
                                };
                                finder.popup();
                            });
                        });
                    </script>
                   
                </td>
            </tr>
            
           
           
        </table>
        <div>
            <%= Html.TextArea("ChiTiet",null, new { @name="ChiTiet" })%>
            <script type="text/javascript">

                CKEDITOR.replace('ChiTiet',
             {
                 htmlEncodeOutput: true,
                 enterMode: CKEDITOR.ENTER_BR,
                 filebrowserImageBrowseUrl: '/ckfinder/ckfinder.html?type=Images',
                 filebrowserImageUploadUrl: '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images'
             });
          
            </script>
        </div>
    </fieldset>
    <% } %>
</asp:Content>
